//  Created by 邓盛明 on 2021/11/25.
//  Copyright © 2021 Talkfun. All rights reserved.
//

import UIKit
import AFNetworking

import TalkFunBarrageRenderer

class TalkfunViewLargeBack: UIViewController,TalkfunSDKPlaybackDelegate,UIScrollViewDelegate,UIGestureRecognizerDelegate,TF_HorBackChatTableDelegate,TF_BackChatTableDelegate,TF_BackNetworkSelectDelegate {

    @objc public var playbackID:String = ""
    @objc public var access_token:String = ""
    
    @objc public var logo:String = ""
    @objc public var courseName:String = ""
    
    @objc public var downloadCompleted:Bool = false
    @objc public var TF_isStatusBarHidden:Bool = false
    let superView = UIView()
    var talkfunSDK = TalkfunSDKPlayback.shareInstance()
    var pptView:UIView = UIView()
    var gestureBGView = TF_PlayBackPPTView.init()
    var isOrientationLandscape:Bool = false //横竖屏
    let cameraView = UIView()
    var originPPTFrame:CGRect?
    let chatContrller = TF_BackChatController.init()
    let questionContrller = TF_BackQuestionController.init()
    let chapterController = TF_ChapterViewController.init()
    //记录摄像头是否全屏
    var isCameraFullScreen:Bool = false
    //是否切换了容器
    var isExchanged:Bool = false
    var playDuration:CGFloat = 0;//播放了多少秒
    var liveLong:CGFloat = 0; //记录播放时长
    var layer:CATextLayer = CATextLayer()
    var layerTimer:Timer!
    let advertView = TF_AdvertView.init()
    var origin:Int32 = 0 //记录原点
    var direction:NSInteger = 0 //5//还同记录方向
    var lastVolume:CGFloat = 1 // 上一次调节音量时的音量大小
    var playbackChat  = NSMutableArray()
    var isIphoneX:CGFloat = 0
    var isiphoneBottomX:CGFloat = 0;
    let kuaiJinView = TF_kuaijinView.init()
    let horChapterView = TF_HorChapterView.init()
    let maskView = UIView.init()
    var albumController:TF_AlbumController!
   
    override func viewDidLoad() {
        super.viewDidLoad()
      
        self.portraitUI()
    
        self.view.addSubview(self.superView)
        self.superView.frame = self.getCalculateViewFrame(self.isOrientationLandscape)

        self.TF_isStatusBarHidden = UIApplication.shared.isStatusBarHidden
        
        UIApplication.shared.isStatusBarHidden = false
        
        if  self.navigationController != nil {
         self.navigationController?.setNavigationBarHidden(true, animated: true)
        }
        self.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
        UIApplication.shared.isIdleTimerDisabled = true

        self.getAccessToken()
        
        self.createUI()
      
        NotificationCenter.default.addObserver(self, selector: #selector(self.deviceOrientationChange), name: Notification.Name(UIDevice.orientationDidChangeNotification.rawValue), object: nil)
    }
    func portraitUI()
    {
        UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
        UIApplication.shared.statusBarOrientation = .portrait
        
        UIViewController.attemptRotationToDeviceOrientation()
    }
    
    
    @objc func deviceOrientationChange()
    {

        if self.navigationController != nil  {
           // 本来就是竖屏不再再设置竖屏
            let deviceOrientation = UIApplication.shared.statusBarOrientation
            if self.navigationController != nil {
                //本来就是竖屏不再再设置竖屏
                if self.isOrientationLandscape==false  {
                    
                    if deviceOrientation == .portrait || deviceOrientation == .portraitUpsideDown  {
                        return
                    }
                    if deviceOrientation == .landscapeLeft {
                        self.portraitUI()
                        return
                    }
                    
                }
                
                if (self.isOrientationLandscape){
                    if (deviceOrientation == .landscapeLeft || deviceOrientation == .landscapeRight) {
                        return
                    }
                   
                }
                self.view.endEditing(true)

                if self.isOrientationLandscape {
                    self.orientationPortrait()
                }else
                {
                    self.orientationLandscape()
                    
                }
               

            }
         
    
              
        }
      

    }
    //竖屏
    func system_orientationPortrait() {
        self.buttonView.isHidden = false
        self.pptsFunctionView.fullScreenBtn.isSelected = false
        self.pptsFunctionView.fullScreenBtn.setImage(UIImage.init(named: "HTLive.bundle/mask_icon_max"), for: .normal)
        
        self.orientationPortrait(portrait: true)
        self.updateChrysanthemum()
    }
    
    //横屏
    func system_orientationLandscape() {
        self.buttonView.isHidden = true
        self.pptsFunctionView.fullScreenBtn.isSelected = true
        self.pptsFunctionView.fullScreenBtn.setImage(UIImage.init(named: "HTLive.bundle/mask_icon_nrmal"), for: .normal)
        
        self.orientationPortrait(portrait: false)
        self.updateChrysanthemum()
    }
    // 控制器的view即将显示的时候调用
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.addLoadingView()
    }
    // 控制器的view完全消失的时候调用
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        if  self.navigationController != nil {
            self.navigationController?.setNavigationBarHidden(false, animated: true)
        }
       
    }
    
    func loadingViewUI()
    
    {
        self.view.addSubview(self.loadingView)
        DispatchQueue.main.asyncAfter(deadline: .now()+1.5, execute:
        {
            self.loadingView.removeFromSuperview()
        })
    }
    func addLoadingView()  {

        if (self.playbackID != "" )
        {
       
            guard let s2 = Int(self.playbackID) else { return  }
            let Courses:NSDictionary = TFCourseManagement.getLogoUrl(s2) as NSDictionary
            //读取
            if Courses.count > 0 {
                let logoUrl = Courses["url"] as! String
                let courseName = Courses["title"] as! String
                self.loadingView.configLogo(logoUrl: logoUrl, courseName: courseName)
                
                self.loadingViewUI()
                
            } else {
               
                if(self.logo.count>0)
                {
                    //保存
                    self.loadingView.configLogo(logoUrl: self.logo, courseName: self.courseName)
                    //缓存用户数据
                    TFCourseManagement.saveLogoUrl(self.logo, roomId: s2, title: self.courseName)

                    self.loadingViewUI()
                }
           
          }
        
    }
    }
    func getAccessToken() {
        if (self.access_token != "" ) {
            self.configViewWithAccessToken(token: self.access_token)
        }else
        {
            self.TF_toast("token不能为空")
        }
    }

    func configViewWithAccessToken(token:String) {

        //TODO:初始化SDK-----------------
        let param = TalkfunSDKPlaybackInitParams.init()
        param.accessToken = self.access_token
        param.playbackID = playbackID
        //禁止课程自动播放
//        param.autoplay = false
        
        self.talkfunSDK.enterRoom(param)
   
        self.talkfunSDK.delegate = self

        let pptViewY = self.getPptViewY()
        self.pptView = UIView.init()
        self.pptView.frame = CGRect(x:0,y:pptViewY,width:self.superView.frame.size.width,height:self.superView.frame.size.width*3/4.0)
     
        self.pptView.backgroundColor = UIColor(red: 35/255.0, green: 39/255.0, blue: 57/255.0, alpha: 1.0)

        self.superView.addSubview(self.pptView)
        
    
        self.gestureBGView.frame = CGRect(x:0,y:pptViewY,width:self.superView.frame.size.width,height:self.superView.frame.size.width*3/4.0)
      
        self.superView.addSubview(self.gestureBGView)
   
        self.gestureBGView.tapGestueBlock = { [weak self] in
            guard let `self` = self else {
                return
            }
            self.pptsFunctionView.isHidden = !self.pptsFunctionView.isHidden;
            self.pptsFunctionView.ShowmultipleView(show: false)

        }
        
        self.gestureBGView.doubleTapGestureBlock = { [weak self](tap:UITapGestureRecognizer) in
            guard let `self` = self else {
                return
            }
            self.pptDoubleTapGR(DoubleTap: tap)
            
        }

        self.gestureBGView.panGestueBlock = {
            [weak self](pan:UIPanGestureRecognizer) in
            guard let `self` = self else {
                return
            }
            self.pptPanGR(pptPan: pan)
           
        }
        //2.把ppt容器给SDK（要显示ppt区域的必须部分）
        self.talkfunSDK.configurePPTContainerView(self.pptView)
        
        //cameraView容器
        //超出主层边框的都会被裁减调用
          //设置裁剪
        self.cameraView.layer.masksToBounds =  true
        // 圆角半径  能把一个下正文体,改成圆形
        self.cameraView.layer.cornerRadius = 4
        
        self.cameraView.frame = CGRect(x:self.superView.frame.size.width-150,y:self.pptView.frame.maxY+40,width:150,height:150)
     
        if (self.isPad()) {
            self.cameraView.frame = CGRect(x:self.superView.frame.size.width*0.7,y:self.pptView.frame.maxY+40,width:self.superView.frame.size.width*0.3,height:self.superView.frame.size.width*0.3*3/4.0)
            }
        
        self.cameraView.backgroundColor = UIColor.black
            //首先把容器隐藏
        self.cameraView.isHidden = true;
        
        //3.把ppt容器给SDK（要显示摄像头区域的必须部分）
        self.talkfunSDK.configureCameraContainerView(self.cameraView)
     
        //View 添加手势
        self.addGestureOn()
        if param.autoplay == false {
            self.pptsFunctionView.stopBtn.isSelected = true
        }
    
  
    }
    // MARK: - 手势添加
    func addGestureOn() {
        
        
        //摄像头加手势
        let panGR = UIPanGestureRecognizer.init(target: self, action: #selector(TalkfunViewLargeBack.objectDidDragged(sender:)))
     
        panGR.maximumNumberOfTouches = 2;
        self.cameraView.addGestureRecognizer(panGR)
        
        let tap = UIGestureRecognizer.init(target: self, action: #selector(TalkfunViewLargeBack.tap(sender:)))
       
        self.cameraView.addGestureRecognizer(tap)

        self.originPPTFrame = self.pptView.frame;
    }
    
    @objc func objectDidDragged(sender:UIPanGestureRecognizer) {
        
        if sender.state == UIGestureRecognizer.State.changed {
            //注意，这里取得的参照坐标系是该对象的上层View的坐标。
            let offset = sender.translation(in: self.cameraView)
            let draggableObj = self.cameraView
      
            var finalX:CGFloat        = draggableObj.center.x + offset.x;
            var finalY:CGFloat        = draggableObj.center.y + offset.y;
            let minX :CGFloat         = self.cameraView.frame.size.width / 2.0;
            let maxX :CGFloat         = self.superView.bounds.size.width - (self.cameraView.frame.size.width / 2.0);
            let minY :CGFloat         = self.cameraView.frame.size.height / 2;
            let maxY :CGFloat         = self.superView.bounds.size.height - (self.cameraView.frame.size.height / 2.0);
            
            if(finalX < minX){
                finalX = minX;
            }else if(finalX > maxX){
                finalX = maxX;
            }
            if(finalY < minY){
                finalY = minY;
            }else if(finalY > maxY){
                finalY = maxY;
            }
            //通过计算偏移量来设定draggableObj的新坐
            draggableObj.center = CGPoint(x: finalX, y: finalY)
            //初始化sender中的坐标位置。如果不初始化，移动坐标会一直积累起来。
            sender.setTranslation(CGPoint(x: 0, y: 0), in: self.cameraView)
        }
    
    }
    @objc func tap(sender:UITapGestureRecognizer) {
        //收键盘
        UIApplication.shared.sendAction(#selector(resignFirstResponder), to: nil, from: nil, for: nil)
         var frame:CGRect!
        if self.isCameraFullScreen == false {
            self.isCameraFullScreen = true
          
            //先保存原来cameraView的frame的大小
            frame = self.cameraView.frame
            UIView.animate(withDuration: 0.25) {
                self.cameraView.transform = CGAffineTransform.identity
                self.cameraView.frame = CGRect(x: 0, y: 0, width: self.superView.frame.size.width, height: self.superView.frame.size.height)
                self.updateChrysanthemum()
            };
        } else {
            self.isCameraFullScreen = false
            UIView.animate(withDuration: 0.25) {
                self.isCameraFullScreen = false
                self.cameraView.frame = frame
                self.updateChrysanthemum()
                
            }
        }

    }
    
    func pptDoubleTapGR(DoubleTap:UITapGestureRecognizer) {
        
        if DoubleTap.state == UIGestureRecognizer.State.ended {
           
            let location =  DoubleTap.location(in: self.pptView)
            if (!self.pptsFunctionView.isHidden && (location.y<50||location.y>self.pptView.frame.size.height-50)) {
                return;
            }
        }

    }
    
    func pinchGR(pinch:UIPinchGestureRecognizer) {
        if (self.isCameraFullScreen == true) {
            return;
        }
        let scale:CGFloat = pinch.scale;
        var lastScale:CGFloat = 1;
        if (pinch.state == UIGestureRecognizer.State.began) {
            lastScale = 1;
        }
      let  cameraViewX: CGFloat  = self.cameraView.frame.origin.x;
      let  cameraViewY:CGFloat = self.cameraView.frame.origin.y;
      let  cameraViewW:CGFloat = self.cameraView.frame.size.width;
      let  cameraViewH:CGFloat = self.cameraView.frame.size.height;
        
        if (scale > 1 && (cameraViewX < 0 || (cameraViewX + cameraViewW) > self.superView.bounds.size.width || cameraViewY < 0 || (cameraViewY + cameraViewH) > self.superView.bounds.size.height)) {
            return;
        }
        
        self.cameraView.transform = CGAffineTransform.init(scaleX: scale/lastScale, y: scale/lastScale)
        lastScale = scale;
    }
    
    // MARK: - 快进快退手势
    func pptPanGR(pptPan:UIPanGestureRecognizer)  {
        self.pptsFunctionView.isHidden = true;
        let divSpeed :CGFloat = 4;
        var isValue:Bool = true;
        if (pptPan.state == UIGestureRecognizer.State.began) {

            //原点
            self.origin = 0;
            //第一次点击,设置默认值
            self.direction = 5;
            self.lastVolume =  TF_Modulation.shareInstance().getCurrentVolume
           
            let location = pptPan.translation(in: self.pptView)
           
            if (!self.pptsFunctionView.isHidden && (location.y<50||location.y>self.pptView.frame.size.height-50)) {
                isValue = false;
                return;
            }
        }else if (pptPan.state == UIGestureRecognizer.State.changed) {

            if (isValue == false) {
                
            }else
            {
                let offset = pptPan.translation(in: self.view)
                //第一次判断,
                if ( self.direction == 5) {
                    
                    //判断方向
                  self.direction = self.commitTranslation(point: offset)
        
                }
                //上下
                if (self.direction == 3) {
                  
                    self.volumeAdjustment(curP: offset)
                  
                }
                
                //左右
                if (self.direction == 1 ) {
                  
                    let X:CGFloat = offset.x;
                    var kuai:CGFloat = X/divSpeed;
                    let duration:CGFloat = CGFloat(self.pptsFunctionView.slider.value) + kuai;
                    if (duration > self.liveLong) {
                        kuai = self.liveLong-CGFloat(self.pptsFunctionView.slider.value)
                    }else if (kuai < 0 && CGFloat(self.pptsFunctionView.slider.value) < CGFloat(fabs(kuai))){
                        kuai = CGFloat(self.pptsFunctionView.slider.value)
                    }

                 self.playDuration = duration;
                 self.pptsFunctionView.startLab.text = self.transToHourMinSec(time: Float(duration))
                
                    self.kuaiJinView.isHidden = false
                  
                    let str1:String = self.pptsFunctionView.startLab.text!
                    let str2:String = self.pptsFunctionView.endLab.text!
                    self.kuaiJinView.kuai(kuai, timeLabel: str1, totalTimeLabel: str2)
               
             
                }
            }
           

           
        }else if (pptPan.state == UIGestureRecognizer.State.ended){

            if (isValue == false) {
                self.direction = 5
                isValue = true
                
            }else
            {
                if (self.direction == 1) {
                     self.direction = 5;
                    let offset = pptPan.translation(in: self.view)
                    
                    let X:CGFloat = offset.x;
                    var duration :CGFloat = CGFloat(self.pptsFunctionView.slider.value) + X/divSpeed;
                    if (duration > self.liveLong) {
                        duration = self.liveLong;
                    }else if (duration < 0){
                        duration = 0;
                    }
                    if (fabs(X/divSpeed)>=1.0) {
                        self.seek(duration: duration)
                       
                    }
                    self.kuaiJinView.isHidden = true
                    
                }
            }

           
           
        }
        
    }
    
    /** 判断手势方向  */
    func commitTranslation(point:CGPoint) -> NSInteger {
        
        //负数变正数
        let absX:Double = fabs(point.x);
         //负数变正数
        let absY:Double = fabs(point.y);

         if (absX > absY ) {

            return 1
        }
 
        
        return 3
    }
    
    func volumeAdjustment(curP:CGPoint) {
        var Y:CGFloat = 0;
        if (curP.y>0) {
            Y  =  curP.y -  CGFloat(self.origin)
        }else{
            
            Y  = CGFloat(abs(Int32(Int32(curP.y)-self.origin)))
        }
        
        if ( Y > 10) {
            
            self.origin = Int32(curP.y)
            
            
            if(curP.y>0&&self.lastVolume>0){
             
                self.lastVolume = self.lastVolume - 0.08;
          

            }else if(self.lastVolume<1){
          
                self.lastVolume = self.lastVolume + 0.08;
                    
                
            }
            //设置音量
            TF_Modulation.shareInstance().setVolume(self.lastVolume)
            
        }
        
    }
    
    func seek(duration:CGFloat)  {
      
        self.talkfunSDK.seek(duration)
        self.playDuration = duration;
        self.pptsFunctionView.setDuration(duration: Float(duration))
        
        //清空当前的所有弹幕
        self.barrageRender.bulletSwitch = false
       
    }
    func updateChrysanthemum() {
        if self.isExchanged==true {
            self.activityIndicator.frame = CGRect(x: 0, y: 0, width: self.pptView.frame.size.width, height: self.pptView.frame.size.height)

            self.pptView.addSubview(self.activityIndicator)
            self.pptView.bringSubviewToFront(self.activityIndicator)
    
        }else{
            self.activityIndicator.frame = CGRect(x: 0, y: 0, width: self.cameraView.frame.size.width, height: self.cameraView.frame.size.height)

            self.cameraView.addSubview(self.activityIndicator)
            self.cameraView.bringSubviewToFront(self.activityIndicator)
        }
    }
    
    func isPad() -> Bool {

        var pad = false as Bool
           if UIDevice.current.userInterfaceIdiom == .pad {
               pad = true
           }
    
         return pad

    }
    //全屏点击
    @objc func fullScreenClick(btn:UIButton)  {
        
        if btn.isSelected == false {
            UIApplication.shared.statusBarOrientation = UIInterfaceOrientation.landscapeRight
            self.orientationLandscape()
        } else {
            UIApplication.shared.statusBarOrientation = UIInterfaceOrientation.portrait
            self.orientationPortrait()
        }
        self.advertView.frame = CGRect(x: 0, y: 0, width: self.superView.frame.size.width, height: self.superView.frame.size.height)
        btn.isSelected = !btn.isSelected;
       
    }
    
    // MARK: - 横屏
    func orientationLandscape() {

        self.isOrientationLandscape = true
        self.system_orientationLandscape()

    }
    
    // MARK: - 竖屏
    func orientationPortrait()  {

        self.isOrientationLandscape = false
    
        self.system_orientationPortrait()

    }
    
    func orientationPortrait(portrait:Bool) {
     
      
        self.pptsFunctionView.isOrientationLandscape = !portrait
        
        if (self.isOrientationLandscape) {

                //强制翻转屏幕，Home键在右边。
        UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
            
        UIApplication.shared.statusBarOrientation = .landscapeRight
            
        UIViewController.attemptRotationToDeviceOrientation()
            
            
            UIApplication.shared.isStatusBarHidden = true
        }else{
          
            
            UIApplication.shared.isStatusBarHidden = false
            
            self.portraitUI()

        }
        
        UIViewController.attemptRotationToDeviceOrientation()
        
        self.superView.frame = self.getCalculateViewFrame(self.isOrientationLandscape)
        
        let pptViewY = self.getPptViewY()
        
        if portrait {
            self.pptView.frame = CGRect(x: 0, y: pptViewY, width: self.superView.bounds.size.width, height: self.superView.bounds.size.width * 3 / 4)
        } else {

            self.pptView.frame = CGRect(x: 0, y: pptViewY, width: self.superView.bounds.size.width, height: self.superView.bounds.size.height - pptViewY)

        }
        self.barrageRender.frame = self.pptView.bounds
        
        if self.isPad() {
            if portrait {
                self.cameraView.frame = CGRect(x: self.superView.frame.size.width * 0.7, y: self.pptView.frame.maxY+40, width: self.superView.frame.size.width * 0.3, height: self.superView.frame.size.width * 0.3*3/4.0)
            } else {

                    self.cameraView.frame = CGRect(x: self.pptView.frame.maxX-self.superView.frame.size.height*3/10.0, y: self.pptView.frame.maxY-50-(self.superView.frame.size.height*3/10.0)*3/4.0, width: self.superView.frame.size.height*3/10.0, height: (self.superView.frame.size.height*3/10.0)*3/4.0)

            }
            
        } else {
            var frame = self.cameraView.frame;
            if portrait {
                frame.origin = CGPoint(x: self.superView.frame.size.width-150, y: self.pptView.frame.maxY+40)
            } else {
                frame.origin = CGPoint(x: self.pptView.frame.maxX-self.cameraView.frame.size.width, y: self.pptView.frame.maxY-50-frame.size.height)
            }
            self.cameraView.frame = frame;
            self.pptsFunctionView.totalTimeLabelShow(isshow: !portrait)
           
        }
        self.gestureBGView.frame = self.pptView.frame
      
        self.buttonView.frame = CGRect(x:0,y:self.pptView.frame.maxY,width:self.superView.frame.size.width,height:40)
       
        if (self.buttonView.styleArea == .All) {  //两者都有
            
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*3, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*4, height: 0)
            }
            self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*2, y: 0)
        } else if ( self.buttonView.styleArea == .Chat) {
           
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*2, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*3, height: 0)
            }
            self.chatContrller.view.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.chapterController.view.frame = CGRect(x: self.scrollView.frame.size.width, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.albumController.view.frame = CGRect(x: self.scrollView.frame.size.width*2, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            
            self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
        } else if (self.buttonView.styleArea == .Ask) {
            
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*2, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*3, height: 0)
            }
            self.questionContrller.view.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.chapterController.view.frame = CGRect(x: self.scrollView.frame.size.width, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.albumController.view.frame = CGRect(x: self.scrollView.frame.size.width*2, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            
            self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
        } else if (self.buttonView.styleArea == .None) {
            
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*2, height: 0)
            }
            self.chapterController.view.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.albumController.view.frame = CGRect(x: self.scrollView.frame.size.width, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.scrollView.contentOffset = CGPoint(x: 0, y: 0)
        }
        
        self.buttonView.isHidden = false

        self.buttonView.layoutSubviews()
  
        self.horChatController.frame = CGRect(x: self.isIphoneX, y: self.superView.frame.size.height-192-56-self.isiphoneBottomX, width: 320, height: 192)
        self.horChapterView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        self.horQuestionView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        self.horAlbumView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        self.kuaiJinView.frame = self.pptView.frame;
        self.maskView.frame = self.view.bounds
        if portrait {
            self.scrollView.isHidden = false
            self.buttonView.isHidden = false
            self.horChatController.isHidden = true
            self.horAlbumView.isHidden = true
            self.horQuestionView.isHidden = true
            self.pptsFunctionView.frame = self.gestureBGView.bounds
            self.pptsFunctionView.multipleView.frame = CGRect(x: self.pptsFunctionView.frame.size.width-280, y: self.pptsFunctionView.frame.size.height, width: 280, height: self.pptsFunctionView.frame.size.height)
        } else {
            self.scrollView.isHidden = true
            self.buttonView.isHidden = true
            self.horChatController.isHidden = false
            self.horQuestionView.tableview.reloadData()
            self.horAlbumView.isHidden = false
            self.horQuestionView.isHidden = false
      
            self.pptsFunctionView.frame = CGRect(x: self.isIphoneX, y: 0, width: self.gestureBGView.bounds.size.width-self.isIphoneX, height: self.gestureBGView.bounds.size.height-self.isiphoneBottomX);
            self.pptsFunctionView.multipleView.frame = CGRect(x: self.pptsFunctionView.frame.size.width-88-30, y: self.pptsFunctionView.frame.size.height, width: 88, height: self.pptsFunctionView.frame.size.height)
        }
    
       
        
        if self.maskView.isHidden == false {
            self.showMoreView(show: false)
        }
        
    }
    
    func getPptViewY() -> CGFloat {
        var pptViewY : CGFloat = 0
      
        //刘海屏与是竖屏
        if (self.isNotchScreen) {
            if self.isOrientationLandscape == false  {
                pptViewY = 32;
            } else {
                pptViewY = 0
            }
             
        }else{
            if self.isOrientationLandscape == false {
                pptViewY = 20
            } else {
                pptViewY = 0
            }
        }
        return pptViewY
    }
    
   @objc func closeChapterBtnClick()  {
       self.showChapter(isshow: false)
    }

    func createUI() {
    
        self.createPPTsButton()
        self.createScrollView()
        self.superView.addSubview(self.buttonView)
        
        
        self.maskView.frame = self.view.bounds
        self.maskView.backgroundColor = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.5)
        self.maskView.isHidden = true
        let maskTap = UITapGestureRecognizer.init(target: self, action: #selector(maskViewClickTap))
   
        self.maskView.isUserInteractionEnabled = true;
        self.maskView.addGestureRecognizer(maskTap)
        self.superView.addSubview(self.maskView)
        self.superView.addSubview(self.horQuestionView)
        self.superView.addSubview(self.horChatController)
        self.superView.addSubview(self.horAlbumView)
        self.superView.addSubview(self.cameraView)
        self.horChatController.tapGestueBlock = { [weak self] in
            guard let `self` = self else {
                return
            }
            self.pptsFunctionView.isHidden = !self.pptsFunctionView.isHidden;

        }
        
   
        self.horChapterView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        self.horChapterView.backgroundColor = UIColor.white
        self.superView.addSubview(self.horChapterView)
        self.horChapterView.closetBtn.addTarget(self, action: #selector(closeChapterBtnClick), for: .touchUpInside)
        self.horChapterView.durationBlock = { [weak self](duration,row) in
               guard let `self` = self else {
                   return
               }
            DispatchQueue.main.async {
                self.seek(duration: duration)
                self.horChapterView.refreshUIWithIndex(num: row)
                self.chapterController.refreshUIWithIndex(num: row)
            }
        }
        self.horChapterView.DeselectBlock = {
            [weak self](row) in
                   guard let `self` = self else {
                       return
                   }
                DispatchQueue.main.async {
                  
                    self.horChapterView.refreshUIWithIndex(num: row)
                    self.chapterController.refreshUIWithIndex(num: row)
                }
        }
        
        
        self.horAlbumView.setAlbumBlock = {[weak self](token) in
            guard let `self` = self else {
                return
            }
       
            //新
            let params:TalkfunSDKPlaybackInitParams = TalkfunSDKPlaybackInitParams.init()
            params.accessToken = token
            self.talkfunSDK.enterRoom(params)
            self.pptsFunctionView.slider.value = 0;
      
        }
        
        //广告片头
     
        self.advertView.frame = CGRect(x: 0, y: 0, width: self.superView.frame.size.width, height: self.superView.frame.size.height)
       
        self.advertView.isHidden = true;
        self.advertView.backgroundColor = UIColor(red: 0, green: 0, blue: 0,alpha:1)
        self.superView.addSubview(self.advertView)
        self.talkfunSDK.setADVideoContainer(self.advertView.videoView)
        self.advertView.back.addTarget(self, action: #selector(quitClick), for: .touchUpInside)
        
        self.advertView.prompt.addTarget(self, action: #selector(promptClick(btn:)), for: .touchUpInside)
       
        self.advertView.fullScreen.addTarget(self, action: #selector(fullScreenClick(btn:)), for: .touchUpInside)
       
        
        self.kuaiJinView.frame = self.pptView.frame;
        self.kuaiJinView.isUserInteractionEnabled = true;
        self.kuaiJinView.isHidden = true
        self.pptView.addSubview(self.kuaiJinView)

        
    }
    // MARK: - 控件展示
    
    func showChapter(isshow:Bool) {
        self.horChapterView.isShow = isshow
        UIView.animate(withDuration: 0.25) {[weak self] in
            guard let `self` = self else {
                return
            }
            
            if isshow {
                self.horChapterView.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
                self.maskView.isHidden = false

            } else {
                self.horChapterView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)

            }
        }
    }
    
    func showHorquestion(show:Bool)  {
        self.horQuestionView.isShow = show
        UIView.animate(withDuration: 0.25) {[weak self] in
            guard let `self` = self else {
                return
            }
            
            if show {
                self.horQuestionView.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
                self.maskView.isHidden = false

            } else {
                self.horQuestionView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)

            }
        }
    }
    
    func showhorAlbum(show:Bool)  {
        self.horAlbumView.isShow = show
        UIView.animate(withDuration: 0.25) {[weak self] in
            guard let `self` = self else {
                return
            }
            
            if show {
                self.horAlbumView.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
                self.maskView.isHidden = false

            } else {
                self.horAlbumView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)

            }
        }
    }
    
    // MARK: - 跳过广告
   @objc func promptClick(btn:UIButton) {
       self.talkfunSDK.skipAD()
       self.advertView.isHidden = true;
    }

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        
        
        if ((touch.view?.isKind(of: UISlider.self)) != nil) {
            return true
        }
        
        return true
    }
  
    
    func createPPTsButton() {
        self.gestureBGView.addSubview(self.pptsFunctionView)
        if self.isPad() {
            self.pptsFunctionView.totalTimeLabelShow(isshow: true)
        }
       
    }
    
   @objc func btnScrollClick(btn:UIButton)  {
       self.buttonView.updateFrame(button: btn)
       if btn == self.buttonView.chatBtn {
           self.scrollView.contentOffset = CGPoint(x: 0, y: 0)
       } else if btn == self.buttonView.askBtn {
           if self.buttonView.styleArea == .All {
               self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
           } else {
               self.scrollView.contentOffset = CGPoint(x: 0, y: 0)
           }
           
       } else if btn == self.buttonView.chapter {
           if self.buttonView.styleArea == .All {
               self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*2, y: 0)
           } else if (self.buttonView.styleArea == .Chat) || (self.buttonView.styleArea == .Ask) {
               self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
           } else if self.buttonView.styleArea == .None {
               self.scrollView.contentOffset = CGPoint(x: 0, y: 0)
           }
         
       } else if btn == self.buttonView.albumBtn {
           if self.buttonView.styleArea == .All {
               self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*3, y: 0)
           } else if (self.buttonView.styleArea == .Chat) || (self.buttonView.styleArea == .Ask)  {
               self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*2, y: 0)
           } else if self.buttonView.styleArea == .None {
               self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
           }
          
       }
       
    }
    
   //MARK:  - scrollView 代理方法
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let num:CGFloat = self.scrollView.contentOffset.x/self.scrollView.frame.size.width
       
        
            if num == 0 {
                if (self.buttonView.styleArea == .All) || (self.buttonView.styleArea == .Chat) {
                    self.buttonView.updateFrame(button: self.buttonView.chatBtn)
                } else if self.buttonView.styleArea == .Ask {
                    self.buttonView.updateFrame(button: self.buttonView.askBtn)
                } else if self.buttonView.styleArea == .None {
                    self.buttonView.updateFrame(button: self.buttonView.chapter)
                }
               
                self.scrollView.contentOffset = CGPoint(x: 0, y: 0)
            } else if (num == 1) {
                if self.buttonView.styleArea == .All {
                    self.buttonView.updateFrame(button: self.buttonView.askBtn)
                } else if (self.buttonView.styleArea == .Ask) ||  (self.buttonView.styleArea == .Chat) {
                    self.buttonView.updateFrame(button: self.buttonView.chapter)
                }  else if self.buttonView.styleArea == .None {
                    self.buttonView.updateFrame(button: self.buttonView.albumBtn)
                }
               
                self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
            } else if (num == 2) {
                if self.buttonView.styleArea == .All {
                    self.buttonView.updateFrame(button: self.buttonView.chapter)
                } else {
                    self.buttonView.updateFrame(button: self.buttonView.albumBtn)
                }
              
                self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*2, y: 0)
            } else if (num == 3) {
                self.buttonView.updateFrame(button: self.buttonView.albumBtn)
                self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*3, y: 0)
            }
      
       
     
       
    }
    
    func createScrollView() {
        self.superView.addSubview(self.scrollView)
        
        for i in 0..<4 {
       
            //聊天页面
            if i == 0 {
               
      
                self.chatContrller.view.frame =  CGRect(x:0,y:0,width:self.scrollView.frame.size.width,height:self.scrollView.frame.size.height)
                self.chatContrller.view.backgroundColor =  UIColor(red: 242/255.0, green: 242/255.0, blue: 242/255.0, alpha: 1.0)
                self.chatContrller.view.tag = 300
                self.chatContrller.delegate = self;
                self.scrollView.addSubview(self.chatContrller.view)
                self.addChild(self.chatContrller)
                self.chatContrller.createUI()
            }
            //提问
           else  if i == 1 {
            
                
                self.questionContrller.view.frame =  CGRect(x:self.scrollView.frame.size.width,y:0,width:self.scrollView.frame.size.width,height:self.scrollView.frame.size.height)
               self.questionContrller.view.backgroundColor = UIColor(red: 242/255.0, green: 242/255.0, blue: 242/255.0, alpha: 1.0)
              
                self.scrollView.addSubview(self.questionContrller.view)
               self.addChild(self.questionContrller)
                self.questionContrller.createUI()
            } else if i == 2 {  //章节
                
                self.chapterController.view.frame =  CGRect(x:self.scrollView.frame.size.width*2,y:0,width:self.scrollView.frame.size.width,height:self.scrollView.frame.size.height)
                self.chapterController.view.backgroundColor = UIColor(red: 242/255.0, green: 242/255.0, blue: 242/255.0, alpha: 1.0)
                self.scrollView.addSubview(self.chapterController.view)
                self.addChild(self.chapterController)
                self.chapterController.createUI()
          
                self.chapterController.durationBlock = { [weak self](duration,row) in
                       guard let `self` = self else {
                           return
                       }
                    DispatchQueue.main.async {
                        self.seek(duration: duration)
                        self.chapterController.refreshUIWithIndex(num: row)
                        self.horChapterView.refreshUIWithIndex(num: row)
                    }
                }
                self.chapterController.DeselectBlock = {
                    [weak self](row) in
                           guard let `self` = self else {
                               return
                           }
                        DispatchQueue.main.async {
                          
                            self.horChapterView.refreshUIWithIndex(num: row)
                            self.chapterController.refreshUIWithIndex(num: row)
                        }
                }
            } else if i == 3 { //专辑
                self.albumController = TF_AlbumController.init()
                self.albumController.view.frame =  CGRect(x:self.scrollView.frame.size.width*3,y:0,width:self.scrollView.frame.size.width,height:self.scrollView.frame.size.height)
                self.albumController.view.backgroundColor =  UIColor(red: 242/255.0, green: 242/255.0, blue: 242/255.0, alpha: 1.0)
    

                self.scrollView.addSubview(self.albumController.view)
                self.addChild(self.albumController)
                self.albumController.createUI()
                
                self.albumController.setAlbumBlock = {[weak self](token) in
                    guard let `self` = self else {
                        return
                    }
               
                    //新
                    let params:TalkfunSDKPlaybackInitParams = TalkfunSDKPlaybackInitParams.init()
                    params.accessToken = token
                    self.talkfunSDK.enterRoom(params)
                    self.pptsFunctionView.slider.value = 0;
              
                }
                
                
            }

        }
 

    }
    
    @objc func maskViewClickTap() {
        if self.pptsFunctionView.multipleView.isHidden == false {
            self.pptsFunctionView.multipleView.subviews.forEach { subviews in
                subviews.removeFromSuperview()
            }
            self.pptsFunctionView.multipleView.isHidden = true
        }
        self.maskView.frame = self.view.bounds
        if self.horChapterView.isShow {
            self.showChapter(isshow: false)
           
        }
      
        if self.horQuestionView.isShow {
            self.showHorquestion(show: false)
            
        }
        
        if self.horAlbumView.isShow {
            self.showhorAlbum(show: false)
           
        }
        if self.backNetSelectView.isShow {
            self.showNetWork(show: false)
            return
        }
        self.showMoreView(show: false)
        
        self.url_closeBtnClick()
    }
    
    lazy var buttonView:TF_BackButtonView = {
        
        let btnView = TF_BackButtonView.init()
        btnView.isHidden = true
        btnView.frame = CGRect(x:0,y:self.pptView.frame.maxY,width:self.superView.frame.size.width,height:40)
        btnView.backgroundColor = UIColor.white
        btnView.buttonsAddTarget(target: self, action: #selector(btnScrollClick(btn:)))
        return btnView
    }()
    
    
    lazy var pptsFunctionView:TF_PPTFunction = {
        var ppts = TF_PPTFunction.init()
        ppts.frame = self.pptView.bounds
        if self.downloadCompleted {
            ppts.downloadBtn.isHidden = true
        }

        ppts.multipleView.frame = CGRect(x: ppts.frame.size.width-88-30, y: ppts.frame.size.height, width: 88, height: ppts.frame.size.height)
        ppts.buttonsAddTarget(target: self, action: #selector(TalkfunViewLargeBack.pptsButtonClicked(btn:)))
        ppts.isHidden = false;
        ppts.playbackMode(Mode: true)
        
        ppts.sliderValueBlock = {  [weak self](sliderValue) in
            guard let `self` = self else {
                return
            }
            
            DispatchQueue.main.async {
                self.seek(duration: sliderValue)
            }
          
        }
        
        //单击
        ppts.sliderTapGestureBlock = { [weak self](sliderValue) in
            guard let `self` = self else {
                return
            }
            
            DispatchQueue.main.async {
              
                self.talkfunSDK.seek(sliderValue)
            }
            
        }
        
        //倍数
        ppts.rateBlock = { [weak self](speed) in
            guard let `self` = self else {
                return
            }
            
            self.talkfunSDK.playbackRate = speed
            self.maskView.isHidden = true
        }
        
        //过程中
        ppts.sliderValueChangeBlock = { [weak self](sliderValue) in
            guard let `self` = self else {
                return
            }
            
            self.playDuration = sliderValue;
            self.pptsFunctionView.startLab.text = self.transToHourMinSec(time: Float(sliderValue))
            
        }
        
        return ppts
        
    } ()
    
    // MARK: - 时间转换
    func transToHourMinSec(time: Float) -> String
    {
        let allTime: Int = Int(time)
        var hours = 0
        var minutes = 0
        var seconds = 0
        var hoursText = ""
        var minutesText = ""
        var secondsText = ""
        
        hours = allTime / 3600
        hoursText = hours > 9 ? "\(hours)" : "0\(hours)"
        
        minutes = allTime % 3600 / 60
        minutesText = minutes > 9 ? "\(minutes)" : "0\(minutes)"
        
        seconds = allTime % 3600 % 60
        secondsText = seconds > 9 ? "\(seconds)" : "0\(seconds)"
        
        return "\(hoursText):\(minutesText):\(secondsText)"
    }
    
    lazy var scrollView:UIScrollView = {
        
        let scroll = UIScrollView()
        scroll.frame = CGRect(x:0,y:self.buttonView.frame.maxY,width:self.superView.frame.size.width,height:self.view.frame.self.height-self.buttonView.frame.maxY)
        scroll.backgroundColor = UIColor.white
        scroll.delegate = self
        scroll.isPagingEnabled = true
        return scroll
    }()
    // MARK: - 视频窗口上的菊花
  
    lazy var activityIndicator:UIActivityIndicatorView = {

        if #available(iOS 13.0, *) {
            let act = UIActivityIndicatorView.init(style: UIActivityIndicatorView.Style.large)

            act.isUserInteractionEnabled = false

            return act
        }else
        {
            let act = UIActivityIndicatorView.init(style: UIActivityIndicatorView.Style.whiteLarge)

            act.isUserInteractionEnabled = false

            return act
        }
       
    }()
    
    // MARK: - 弹幕
    lazy var barrageRender:TalkFunBulletView = {
        let barrage  = TalkFunBulletView()
        //开启弹幕权限
        barrage.bulletSwitch = false
        self.pptView.addSubview(barrage)
        barrage.frame =  self.pptView.bounds
        barrage.isUserInteractionEnabled = false
        return barrage
    }()
    
    @objc func quitClick()  {
        
        let alert:UIAlertController = UIAlertController.init(title: "温馨提示", message: "确认退出回放课程?", preferredStyle: .alert)
     
        let cancel:UIAlertAction = UIAlertAction.init(title: "取消", style: .cancel) { action in
           
        }
        let otherAction:UIAlertAction = UIAlertAction.init(title: "确认", style: .default) { action in
            self.quitUI()
            
        }
        alert.addAction(otherAction)
        alert.addAction(cancel)
        self.present(alert, animated: true, completion: nil)
        
    }
    @objc func quitUI()  {
        
     
        UIApplication.shared.isStatusBarHidden = self.TF_isStatusBarHidden
        if self.playbackID.count == 0 {
            
        } else {
            
            let second = NSInteger(self.playDuration)
            let playbackID:NSString = self.playbackID as NSString
            
            let roomId = NSInteger(playbackID.intValue)

            TFCourseManagement.setPlay(roomId, second: second)
           
        }
       
        NotificationCenter.default.removeObserver(self)

       if (self.isOrientationLandscape) {
           UIApplication.shared.statusBarOrientation = UIInterfaceOrientation.portrait
          
       }
        
        self.talkfunSDK.destroy()
  
        self.barrageRender.layer.removeFromSuperlayer()
        
       
        if self.layerTimer != nil {
            self.layerTimer.invalidate()
            self.layerTimer = nil
        }
    
        self.layer.removeFromSuperlayer()
        //返回上一页
        self.TF_dismissUI()
    }
    func getBarrageRenderL(duration:CGFloat) {
        if self.barrageRender.bulletSwitch {
            for index in 0 ..< self.playbackChat.count {
                let dict:TFPlaybackChatData = self.playbackChat[index] as! TFPlaybackChatData
                let time:Int = Int(dict.time)!
               
                if (time == Int(duration)) {
                  
                    self.loadData(str: dict.msg)
                }
                
         
            }
        }
    }
    
    func loadData(str:String)  {
        
        self.barrageRender.initWithContent(str, ontOfSize: 14, textColor: UIColor.white)
    }
    //添加b弹幕聊天数据
    func addPlaybackChat(_ list:NSMutableArray?) {
        self.playbackChat.addObjects(from: list as! [Any])
    }

    func showMoreView(show:Bool)  {
        UIView.animate(withDuration: 0.25) {[weak self] in
            guard let `self` = self else {
                return
            }
            
            if show {
                self.moreView.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
                self.maskView.isHidden = false

                self.moreView.isHidden = false;
            } else {
                self.moreView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)

                self.moreView.isHidden = true
             
            }
        }
    }
    
    // MARK: - 按钮触发事件
    @objc func pptsButtonClicked(btn:UIButton)  {
     
        if btn == self.pptsFunctionView.backBtn { //返回
            if self.isOrientationLandscape {
                self.orientationPortrait()
            } else {
                self.quitClick()
            }
        } else if btn == self.pptsFunctionView.downloadBtn { //下载
            self.downloadBtnClick(btn: btn)
        } else if btn == self.pptsFunctionView.refreshBtn { // 刷新
            self.talkfunSDK.reload()
            self.isExchanged = false
        } else if btn == self.pptsFunctionView.moreBtn { //更多
            self.superView.addSubview(self.moreView)
            self.showMoreView(show: true)
           
        } else if btn == self.pptsFunctionView.stopBtn { //暂停
            btn.isSelected = !btn.isSelected
            if btn.isSelected {
                self.talkfunSDK.pause()
                
            } else {
                self.talkfunSDK.play()
            }
            self.pptsFunctionView.play(isplay: btn.isSelected)
            
        } else if btn == self.pptsFunctionView.multipleBtn {//倍数
            self.pptsFunctionView.ShowmultipleView(show: true)
            self.pptsFunctionView.playbackRate()

        } else if btn == self.pptsFunctionView.chapter {//章节
            self.showChapter(isshow: true)
        } else if btn == self.pptsFunctionView.fullScreenBtn {//全屏

            self.orientationLandscape()
        } else if btn == self.pptsFunctionView.barrageBtn {//弹幕
            
            btn.isSelected = !btn.isSelected;
            if (!btn.isSelected) {
                self.barrageRender.bulletSwitch = false;
               
            }else{
                self.barrageRender.bulletSwitch = true;
               
            }
            
        } else if btn == self.pptsFunctionView.chatBtn {//聊天区域
            btn.isSelected = !btn.isSelected
            if btn.isSelected {
                self.horChatController.isHidden  = true
            } else {
                self.horChatController.isHidden  = false
            }
        } else if btn == self.pptsFunctionView.chuangkou_Btn {//窗口区域
            btn.isSelected = !btn.isSelected
            
            if (btn.isSelected) {
                self.cameraView.isHidden = true;
            } else {
                self.cameraView.isHidden = false;
            }
        }
    }
    
    func downloadBtnClick(btn:UIButton) {
        
        if self.playbackID.count == 0 {
            
        } else {
            let contains:Bool = self.downloadManager.containsPlaybackID(self.playbackID)
            if contains {
              
                self.TF_toast("该回放已下载")
                return
            }
            
            //网络监听
            let status:AFNetworkReachabilityStatus = AFNetworkReachabilityManager.shared().networkReachabilityStatus
            if status == AFNetworkReachabilityStatus.notReachable {
                let alert:UIAlertController = UIAlertController.init(title: "温馨提示", message: "网络已断开", preferredStyle: .alert)
                let otherAction:UIAlertAction = UIAlertAction.init(title: "确认", style: .default) { action in
                    
                }
                alert.addAction(otherAction)
                if self.isPad() {
                    alert.popoverPresentationController?.sourceView = self.view
                    alert.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: 1.0, height: 1.0)
                }
                self.present(alert, animated: true, completion: nil)
    
            } else if status == AFNetworkReachabilityStatus.reachableViaWWAN {
                self.networkAlertShow()
            } else {

                
                //创建下载任务
                self.downloadManager.appendDownload(withAccessKey: self.access_token , playbackID: self.playbackID, title: "")
                //启动下载
                self.downloadManager.startDownload(self.playbackID)
                
                self.TF_toast("该回放已下载")
            }
        }
        
      
    }
    
    func networkAlertShow() {

        let alert:UIAlertController = UIAlertController.init(title: "温馨提示", message: "确定使用蜂窝流量下载?", preferredStyle: .alert)
        
        let otherAction:UIAlertAction = UIAlertAction.init(title: "确认", style: .default) {[weak self] (action) in
            
            guard let `self` = self else {
                return
            }
            self.downloadManager.appendDownload(withAccessKey: self.access_token, playbackID: self.playbackID, title: "")
            self.downloadManager.startDownload(self.playbackID)
             
            self.TF_toast("已添加到下载列表")
      
        }
        alert.addAction(otherAction)
        self.present(alert, animated: true, completion: nil)
        
    }
    
    //实现这下面代理方法，可以解决触控点击事件和手势的冲突，包括UITexFiled,UITableView等等控件单击事件不响应问题。
    // MARK: - 生成layer层
    @objc func arc4random_uniformFrame() {
        if self.layerTimer != nil {
            self.layerTimer.invalidate()
            self.layerTimer = nil
        }
        
      
        self.layerTimer = Timer.scheduledTimer(timeInterval: TimeInterval(self.getRandomNumber()), target: self, selector: #selector(TalkfunViewLargeBack.arc4random_uniformFrame), userInfo: nil, repeats: false)
        RunLoop.main.add(self.layerTimer, forMode: RunLoop.Mode.common)
        
        self.layer.frame =  self.getLayerFrame()
    }
    func getLayerFrame() -> CGRect {

        let layerX:CGFloat = self.pptView.frame.size.width - self.layer.frame.size.width;
        let layerY:CGFloat = self.pptView.frame.size.height - self.layer.frame.size.height;
        let rect:CGRect = CGRect(x: CGFloat(arc4random_uniform(UInt32(layerX))), y: CGFloat(arc4random_uniform(UInt32(layerY))), width: self.layer.frame.size.width, height: self.layer.frame.size.height)
        return rect;
    }
    
    func getRandomNumber() -> Int {
        let random = 60 + Int(arc4random_uniform(120))
        return random
    }
    // MARK: - 添加水印
    func addWatermarkLayer() {
        if self.talkfunSDK.roomInfo.mod_theftproof.enable  {
       
            self.layer.removeFromSuperlayer()
                let name:String = self.talkfunSDK.roomInfo.mod_theftproof.msg
            let attrsSize = name.size(withAttributes: [NSAttributedString.Key.font:UIFont.init(name: "Euphemia UCAS", size: 11)!])
                let layerX:CGFloat = self.pptView.frame.size.width - attrsSize.width;
                let layerY:CGFloat = self.pptView.frame.size.height - attrsSize.height;
                let point = CGPoint(x: CGFloat(arc4random_uniform(UInt32(layerX))), y: CGFloat(arc4random_uniform(UInt32(layerY))))
            
            self.layer = CATextLayer.TF_watermark(text: name, font: UIFont.PingFang(size: 11), point: point)
               
                self.pptView.layer.addSublayer(self.layer)
                
                self.layerTimer = Timer.scheduledTimer(timeInterval: TimeInterval(self.getRandomNumber()), target: self, selector: #selector(TalkfunViewLargeBack.arc4random_uniformFrame), userInfo: nil, repeats: false)
            RunLoop.main.add(self.layerTimer, forMode: RunLoop.Mode.common)
           
               

        }
    }
    // MARK: - 提问 章节 聊天
    func mod_playbackinfo_playbackUI() {
        
        //聊天
        var chatEnable:Bool = false
        //问答
        var qaEnable:Bool  = false
        if (self.talkfunSDK.roomInfo.mod_playbackinfo_playback.enable==true) {
            chatEnable = self.talkfunSDK.roomInfo.mod_playbackinfo_playback.config.chat.enable
      
            qaEnable = self.talkfunSDK.roomInfo.mod_playbackinfo_playback.config.qa.enable
        }
        if ((chatEnable==true) && (qaEnable==true)) {  //两者都有
            self.buttonView.styleArea = .All
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*3, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*4, height: 0)
            }
            self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width*2, y: 0)
        } else if ((chatEnable==true) && (qaEnable==false)) {
            self.buttonView.styleArea = .Chat
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*2, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*3, height: 0)
            }
            self.chatContrller.view.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.chapterController.view.frame = CGRect(x: self.scrollView.frame.size.width, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.albumController.view.frame = CGRect(x: self.scrollView.frame.size.width*2, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            
            self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
        } else if ((chatEnable==false) && (qaEnable == true)) {
            self.buttonView.styleArea = .Ask
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*2, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*3, height: 0)
            }
            self.questionContrller.view.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.chapterController.view.frame = CGRect(x: self.scrollView.frame.size.width, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.albumController.view.frame = CGRect(x: self.scrollView.frame.size.width*2, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            
            self.scrollView.contentOffset = CGPoint(x: self.scrollView.frame.size.width, y: 0)
        } else if ((chatEnable == false) && (qaEnable == false)) {
            self.buttonView.styleArea = .None
            if self.buttonView.albumBtn.isHidden {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width, height: 0)
            } else {
                self.scrollView.contentSize = CGSize(width: self.scrollView.frame.width*2, height: 0)
            }
            self.chapterController.view.frame = CGRect(x: 0, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.albumController.view.frame = CGRect(x: self.scrollView.frame.size.width, y: 0, width: self.scrollView.frame.size.width, height: self.scrollView.frame.size.height)
            self.scrollView.contentOffset = CGPoint(x: 0, y: 0)
        }
        
        self.buttonView.isHidden = false

        self.buttonView.layoutSubviews()
        
   
    }
    // MARK: 房间事件回调
    func onEnterRoom(_ code:NSInteger,result error:TFError) {
        
        if  code == 0 {
            print("uid====>",self.talkfunSDK.roomInfo.myInfo.uid)
            
            
            self.addWatermarkLayer()
            self.liveLong = self.talkfunSDK.roomInfo.totalTime;
            self.pptsFunctionView.slider.maximumValue = Float(self.liveLong);
            
            if self.playbackID.count == 0 {
                
            } else {
                guard let t = Int(self.playbackID) else { return  }
                let second:CGFloat = CGFloat(TFCourseManagement.getPlayProgress(t))
                if second>0 {
                    self.talkfunSDK.seek(second)
                }
            }
         

         //提问 章节 聊天
        self.mod_playbackinfo_playbackUI()
        }
        else
        {
            self.TF_alertController(error.msg)
        }
        
    }
    // MARK: 播放状态发生变化时候调用
    func playStatusChange(_ status: TalkfunPlayStatus) {
       //视频播放失败
        if(status == TalkfunPlayStatusError)
        {
            
            
        }
        
    }
    // MARK: - 视频播放状态改变  -黑屏加菊花时用到
    func playerLoadStateDidChange(_ loadState:TalkfunPlayerLoadState) {
        self.updateChrysanthemum()
        
        if (loadState == TalkfunPlayerLoadState.stalled) {
              //  NSLog(@"发生卡顿，显示菊花");
             self.activityIndicator.startAnimating()
             self.activityIndicator.isHidden = false;
             
         }else
         {
             self.activityIndicator.stopAnimating()
            // NSLog(@"正常播放，移除菊花");
             self.activityIndicator.isHidden = true
//             
         }
    }
    /**
     *  广告播放总时长
     *  是否可跳过广告
     */
    func onADPrepare(_ model:TalkfunADConfig) {
        self.advertView.isHidden = false;
        if self.playbackID.count == 0 {
            
        } else {
            
            self.advertView.advertisingPlayStart(model: model, playbackID: self.playbackID)
        }
       
    }
    /**
     *
     *  广告播放倒计时
     */
    func onADCountDownTime(_ duration: Int) {

        if self.playbackID.count == 0 {
            
        } else {
          
            self.advertView.setSecond(duration: duration, playbackID: self.playbackID)
        }
    }
    /**
     *
     *  广告播放状态改变
     */
    // MARK: - 广告播放状态改变
    func onADVideoStatusChange(_ loadState:TalkfunMultiMediaStatusChangeListener) {
        if (loadState == TalkfunMultiMediaStatusChangeListenerComplate) {
            if self.playbackID.count == 0 {
            
            } else {
     
                self.advertView.advertisingPlaybackCompleted(playbackID: self.playbackID)
            }
         
            
        }else if (loadState == TalkfunMultiMediaStatusChangeListenerError) {
     
            let alert:UIAlertController = UIAlertController.init(title: "温馨提示", message: "广告加载失败", preferredStyle: .alert)
            let otherAction:UIAlertAction = UIAlertAction.init(title: "确认", style: .default) { action in
                
            }
            alert.addAction(otherAction)
            if self.isPad() {
                alert.popoverPresentationController?.sourceView = self.view
                alert.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: 1.0, height: 1.0)
            }
            self.present(alert, animated: true, completion: nil)

          
        }
    }
    
    func onVodDuration(_ duration:CGFloat) {
        //相差5秒以上才记录
        
        if (duration > self.playDuration+5) {
            self.playDuration = duration
        }
     
        if self.playbackID.count == 0 {
            
        } else {
            let second = NSInteger(self.playDuration)
            let playbackID:NSString = self.playbackID as NSString
            
            let roomId = NSInteger(playbackID.intValue)

            TFCourseManagement.setPlay(roomId, second: second)
        }
       
        //获取弹幕然后弹出来
        self.getBarrageRenderL(duration: duration)
        self.pptsFunctionView.setDuration(duration: Float(duration))
        
        self.chapterController.refreshUIWithDuration(duration: duration)
        self.horChapterView.refreshUIWithDuration(duration: duration)
    }
    
    // MARK: - 回放停止播放
    func onVodStop()  {
       
        self.pptsFunctionView.play(isplay: false)
        self.pptsFunctionView.stopBtn.isSelected = true
    }
    
    // MARK: -  回放开始播放
    func onVodStart() {
       
        self.pptsFunctionView.play(isplay: true)
    }
    
    
    // MARK: - 视频开始播放
    func onVodPlay() {
       
        self.pptsFunctionView.play(isplay: true)
     
        self.pptsFunctionView.slider.isUserInteractionEnabled = true;
        
        self.tipsLabel.removeFromSuperview()
   
    }
    // MARK: - 桌面分享开始
    func onLiveDesktopStart() {
        self.cameraView.isHidden = true;
    }
    // MARK: - 桌面分享结束
    func onLiveDesktopStop() {
        self.cameraView.isHidden = false;
    }
    
    // MARK: - 摄像头开启
    func onCameraShow() {
        
        //不是桌面模式
        if self.talkfunSDK.liveMode == TalkfunLiveModeDesktop {
            self.cameraView.isHidden = true;
        }else
        {
            self.cameraView.isHidden = false;
        }
        
    }
    
    // MARK: - 摄像头关闭
    func onCameraHide()  {
        //不是桌面模式
        if (self.talkfunSDK.liveMode != TalkfunLiveModeDesktop) {
            self.cameraView.isHidden = true;
        }else{
            if (self.isExchanged) {
                self.talkfunSDK.exchangePPTAndCameraContainer()
              
                self.isExchanged = false;
            }
            self.cameraView.isHidden = false;
        }

    }
    // MARK: - 章节

    func onVodChapterList( _ list:NSMutableArray)  {
        self.chapterController.updateChapter(list: list)
        self.horChapterView.updateChapter(list: list)
    }
    // MARK: - 专辑
    func onAlbumList(_ list: NSMutableArray)  {
        if list.count == 0 {
            self.buttonView.albumBtn.isHidden = true
            self.moreView.AlbumBtn.isHidden = true
        } else {
            self.buttonView.albumBtn.isHidden = false
            self.moreView.AlbumBtn.isHidden = false
            self.horAlbumView.updateAlbum(list: list)
            self.albumController.updateAlbum(list: list)
            
        }
     
       
    }
    
    // MARK: - 聊天列表
    func onVodChatList(_ list:NSMutableArray)  {

        self.chatContrller.datasource.removeAll()
        self.horChatController.datasource.removeAll()
        list.forEach({ [weak self] model1 in

            guard let `self` = self else {
                return
            }

            if let model = model1 as? TFPlaybackChatData {
                
                let chat = self.getplayBackLiveData(model: model);
                self.addModel(model: chat)
  
            }

          })
        self.addPlaybackChat(list)
        self.chatContrller.tableview.reloadData()
        self.horChatController.tableview.reloadData()
    
    }
    func addModel(model:TF_BackChatLiveData) {
        
        self.chatContrller.updatePlayBackChatData(model: model)
        self.horChatController.updatePlayBackChatData(model: model)
        
    }
    func getplayBackLiveData(model:TFPlaybackChatData) -> TF_BackChatLiveData {
        let chat = TF_BackChatLiveData.init()
        chat.a = model.a;
        chat.uid = model.uid;
        chat.timestamp = model.timestamp
        chat.starttime = model.starttime
        chat.time = model.time
        chat.gid = model.gid
        chat.avatar = model.avatar
        chat.cmd = model.cmd
        chat.role = model.role
        chat.nickname = model.nickname
        chat.msg = model.msg
        chat.status = model.status
        chat.xid = model.xid
        chat.imageURL = model.imageURL
        return chat
    }
    
    // MARK: - 提问列表
    func onVodQuestionsAppendList(_ list:NSMutableArray) {
        self.questionContrller.updatePlayBackQuestion(list: list)
        self.horQuestionView.updatePlayBackQuestion(list: list)

    }
    // MARK: - 播间模式切换
    func onLiveModeChange(status:TFLiveModeChange) {
      let mode:TalkfunLiveMode = status.currentMode
      let mode2:TalkfunLiveMode = status.beforeMode
        
        if (mode != mode2) {
            self.tipsLabel.text = "切换中..."
            self.pptView.addSubview(self.tipsLabel)
            self.pptView.addSubview(self.pptsFunctionView)

        }
    }
    
    lazy var tipsLabel:UILabel = {
        let tips = UILabel.init()
        tips.frame = CGRect(x: 0, y: self.pptsFunctionView.frame.minY, width: 100, height: 30)
        tips.textColor = UIColor.white
        tips.backgroundColor = UIColor.red
        tips.textAlignment = NSTextAlignment.center
        tips.font = UIFont.systemFont(ofSize: 14)
        tips.tag = 222

        return tips
    }()
    
    lazy var loadingView:TF_LoadView = {
        let load = TF_LoadView.init()
        load.frame =  self.view.bounds;
        return load
    }()

 
    lazy var downloadManager:TalkfunDownloadManager = {
        let load = TalkfunDownloadManager.share()
        
        return load
    }()
    
    lazy var moreView:TF_BackMoreView = {
        
        let v = TF_BackMoreView.init()
        v.backgroundColor = UIColor.white
        v.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        v.askRecordBtn.addTarget(self, action: #selector(askRecordClick), for: .touchUpInside)
        v.AlbumBtn.addTarget(self, action: #selector(albumClick), for: .touchUpInside)
        v.closeBtn.addTarget(self, action: #selector(closeMoreViewBtnClick), for: .touchUpInside)
        v.netWorkBtn.addTarget(self, action: #selector(networkselectClick), for: .touchUpInside)
        return v
    }()
    
    lazy var backNetSelectView:TF_BackNetWorkSelectView = {
        let network = TF_BackNetWorkSelectView.init()
        network.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
        network.backgroundColor = UIColor.white
        network.networkdelegate = self
        network.closeBtn.addTarget(self, action: #selector(closeNetWorkSelectView), for: .touchUpInside)
       
        return network
    }()
    @objc func closeNetWorkSelectView() {
        self.showNetWork(show: false)
    }
    func showNetWork(show:Bool) {
        self.backNetSelectView.isShow = show
        UIView.animate(withDuration: 0.25) {[weak self] in
            guard let `self` = self else {
                return
            }
            
            if show {
                self.backNetSelectView.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
                self.maskView.isHidden = false

            } else {
                self.backNetSelectView.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)

            }
        }
       
    }
    @objc func networkselectClick()  {
        self.superView.addSubview(self.backNetSelectView)
       
        self.showNetWork(show: true)
        self.talkfunSDK.getLineList { lineManager in
            self.backNetSelectView.updataNetWork(lineManager)
         
        };
    }
   @objc func closeMoreViewBtnClick() {
       self.showMoreView(show: false)
       self.maskView.isHidden = true
    }
   @objc func askRecordClick()  {
       self.view.bringSubviewToFront(self.horQuestionView)
       self.showHorquestion(show: true)
    }
    
    @objc func albumClick()  {
       
        self.view.bringSubviewToFront(self.horAlbumView)
        self.showhorAlbum(show: true)
     }
    
    lazy var horChatController:TF_HorBackChatView = {
        let chat = TF_HorBackChatView.init()
        chat.backgroundColor = UIColor.clear

        chat.delegate = self
        
        chat.frame = CGRect(x: self.isIphoneX, y: self.superView.frame.size.height-192-56-self.isiphoneBottomX, width: 320, height: 192)
        chat.isHidden = true
        
        return chat
    }()
    
    lazy var horQuestionView:TF_HorBackQuestionView = {
        let question = TF_HorBackQuestionView.init()
        question.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        question.backgroundColor = UIColor.white
        question.isHidden = true
        question.closeBtn.addTarget(self, action: #selector(closeQuestionRecord), for: .touchUpInside)
       
        return question
    }()
    
    @objc func closeQuestionRecord() {
        self.showHorquestion(show: false)
    }
    
    lazy var horAlbumView :TF_AlbumView = {
        let album = TF_AlbumView.init()
        album.backgroundColor = UIColor.white
        album.frame = CGRect(x: self.superView.frame.size.width, y: 0, width: 375, height: self.superView.frame.size.height)
        album.closeBtn.addTarget(self, action: #selector(closeAlbum), for: .touchUpInside)
        album.isHidden = true
        return album
    }()
    
    @objc func closeAlbum() {
    
        self.showhorAlbum(show: false)
    }
    
    lazy var urlAlertView:TF_BackUrlAlertView = {
        let alert = TF_BackUrlAlertView.init()
        if (self.isOrientationLandscape) {
          
            alert.frame = CGRect(x: self.superView.frame.size.width-375, y: 0, width: 375, height: self.superView.frame.size.height)
        } else {
            alert.frame = CGRect(x: 0, y: self.superView.frame.size.height-287, width: self.superView.frame.size.width, height: 287)
        }
    
        alert.backgroundColor = UIColor.white
        alert.commitBtn.addTarget(self, action: #selector(alertUrlCommit), for: .touchUpInside)
 
        let maskLayer = self.getMaskLayer(rect: alert.bounds)
   
         alert.layer.mask = maskLayer;
        alert.closeBtn.addTarget(self, action: #selector(url_closeBtnClick), for: .touchUpInside)
        alert.cancelBtn.addTarget(self, action: #selector(url_closeBtnClick), for: .touchUpInside)
        
        return alert
    }()
    
   @objc func alertUrlCommit() {
       let url:URL = NSURL.init(string: self.urlAlertView.urlLab.text!)! as URL
    
       if #available(iOS 10.0, *) {
           UIApplication.shared.open(url, options: [:], completionHandler: nil)
       }
    }
    
    @objc func url_closeBtnClick() {
        self.urlAlertView.removeFromSuperview()

        self.maskView.isHidden = true
    }
    
    func getMaskLayer(rect:CGRect) -> CAShapeLayer {
        var size = CGSize(width: 10, height: 10)
        if self.isOrientationLandscape {
            size = CGSize(width: 0, height: 0)
        } else {
            size = CGSize(width: 10, height: 10)
        }

        let maskPath = UIBezierPath.init(roundedRect: rect, byRoundingCorners: [.topRight,.topLeft], cornerRadii: size)
        let maskLayer = CAShapeLayer.init()
        maskLayer.frame = rect
        maskLayer.path = maskPath.cgPath
        return maskLayer
    }
    func Backchat_clickToUrl(url: String) {
        if (url.count > 4) {
            self.urlAlertView.urlLab.text = url
            self.superView.addSubview(self.urlAlertView)
            self.superView.bringSubviewToFront(self.urlAlertView)

            self.maskView.isHidden = false

        }
    }
    
    func HorBackchat_clickToUrl(url: String) {
        if (url.count > 4) {
            self.urlAlertView.urlLab.text = url
            self.superView.addSubview(self.urlAlertView)
            self.superView.bringSubviewToFront(self.urlAlertView)

            self.maskView.isHidden = false

        }
    }
    //网络选择代理方法
    func setNetwork(Index:Int) {
        let t = NSNumber(value:Index)
        self.talkfunSDK.setNetworkLine(t)
    }
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent //白色
    }
    // MARK: - 横竖屏支持
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
  
//        if self.navigationController != nil  {
//            return [UIInterfaceOrientationMask.landscapeRight, UIInterfaceOrientationMask.portrait]
//        }else
//        {
            if self.isOrientationLandscape {
                return UIInterfaceOrientationMask.landscapeRight
            }
            return  UIInterfaceOrientationMask.portrait
//        }
        
    }
    
    override var shouldAutorotate: Bool{
        return true
    }
    ////隐藏状态栏
    override var prefersStatusBarHidden: Bool
    {
        return true
    }
    deinit {
        
            print("大班回放没有循环引用")
        }

}

